<?php

class Course_selection extends CI_Controller{
   var $user_id;

    function __construct() {
        parent::__construct();

//        if(!$this->session->userdata('user_id')){
//            $uri = site_url('visitor/home');
//            echo "<script>javascript:alert('Please Login to Your Account'); window.location = '" . $uri . "'</script>";
//            exit;
//        }
       $this->user_id = 1;


        //Set folder to load view (under View folder)
        $this->layouts->set_view_folder('course_selection');

        //Load model
        $this->load->model('course_selection_model');

        //load js and css
        $this->layouts->set_css('datatable/demo_table');
        $this->layouts->set_css('datatable/smoothness/jquery-ui-1.8.4.custom');
        $this->layouts->set_js('jquery.dataTables');
        $this->layouts->set_js('js_courseselection/course');

        //Send base url to view for processing
        $this->view_data['base_url'] = base_url();
    }
    
    function index(){
        $this->Search();
    }
    function Search(){
        $keyword = $this->input->post('keyword');
        $cate = $this->input->post('cate');
        $data['mycourse'] = $this->course_selection_model->mycourse($this->user_id);
        $data['cSearch'] = $this->course_selection_model->cSearch($this->user_id,$keyword, $cate);
        $data['scareer'] = $this->course_selection_model->scareer($this->user_id);
        $this->layouts->view('course_selection_content', $data);
    }

    function Addcourse(){
        $this->course_selection_model->Addcourse($user_id);
        if($query){
            echo "Delete Successfully";
        }else{
            echo "Delete Unsuccessfully";
        }
    }

    function home(){
        $data['mycourse'] = $this->course_selection_model->mycourse($this->user_id);
        $data['mycourse_ss'] = $this->course_selection_model->mycourse_ss($this->user_id);
        $data['scareer'] = $this->course_selection_model->scareer($this->user_id);
        $data['Results'] = $this->course_selection_model->SelectCareerToCourse($this->user_id);
        $this->layouts->view('course_selection_mycourse', $data);
    }

    function deletecourse(){
       $this->load->model('course_selection_model');
       $this->course_selection_model->entry_delete();
       if($query){
            echo "Delete Successfully";
        }else{
            echo "Delete Unsuccessfully";
        }
    }

    function visitor(){
        $this->layouts->view('visitor_page_riasec');
    }

     function confirmSelection(){
        $this->load->model('course_selection_model');
        $ids = $this->input->post('course_id');
        foreach($ids as $id){
        $this->course_selection_model->confirmSelectionModel($id);
        }
        redirect('course_selection/home');
    }

     function selCourse(){
      $data['selected'] = $this->course_selection_model->selCourseModel();
      $this->layouts->view('course_selected', $data);
    }

     function showDesc($course_id) {
        $this->load->model('course_selection_model');
        $data['desc'] = $this->course_selection_model->showDesc($course_id);
        $data['header'] = 'course_selection/course_selection_head';
        $data['content'] = 'course_selection/course_desc';
        $this->load->view('course_selection/course_desc', $data);
    }

    //improved

    function search_cc(){
        $keyword = $this->input->post('keyword');
        $cate = $this->input->post('cate');
        $data['mycourse'] = $this->course_selection_model->mycourse($this->user_id);
        $data['searchcc'] = $this->course_selection_model->searchcc($this->user_id,$keyword, $cate);
        $data['scareer'] = $this->course_selection_model->scareer($this->user_id);
        $this->layouts->view('course_selection_search', $data);
    }
}

?>
